package com.alex.basic.web.struts2;


import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.alex.hibernate.domain.User;
import com.alex.hibernate.manager.UserManager;
import com.alex.operateionLog.annotation.Log;

@Namespace("/")
public class HelloWorldAction extends BasicAction {

	private static final long serialVersionUID = 1908886549450979144L;
	
//	private final static Logger log = LoggerFactory.getLogger(HelloWorldAction.class);
	
	@Autowired
	@Qualifier("userManagerImplHibernate")
	private UserManager userManager;
	
//	@Autowired
//	UserManagerImplHibernate userManagerImplHibernate;
	
	@Log(description="action log")
	public void test() throws Exception{
		User user = new User();
		user.setLoginName("aop");
		user.setPassword("aop");
		userManager.save(user);
		ServletActionContext.getResponse().getWriter().write("abcd");
	}
	
	public void test2() throws Exception{
		User user = new User();
		user.setLoginName("abc");
		user.setPassword("aop");
//		userManagerImplHibernate.save(user);
		userManager.save(user);
		ServletActionContext.getResponse().getWriter().write("abcd");
	}
	
	public void testTransaction(){
		User userLoaded = userManager.get("8a80817b32443d590132443d921c0000");
		userLoaded.setPassword("Password");
		User newUser = new User();
		newUser.setLoginName("newUser");
		newUser.setPassword(userLoaded.getPassword());
		try {
			userManager.save(newUser);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void prepareModel() {
	}

	public Object getModel() {
		return null;
	}
}
